package com.retrozelda.nyanimals;

import android.graphics.RectF;
import android.util.Log;

public class CButton extends CRectangle
{
	RectF	m_Rect;

	@Override
	public Object clone()
	{
		CButton ret = (CButton)super.clone();

		ret.m_Rect = m_Rect;

		return ret;
	}

	public void Init(NyanimalGLSurfaceView game, int posX, int posY, int resourceID)
	{
		super.Init(game);
		LoadTexture(resourceID, game);
		SetPosition(posX, posY);
		SetSize(m_textureWidth, m_textureHeight);

		BuildTouchBox();
	}

	public void BuildTouchBox()
	{
		// build the touch rect
		m_Rect = new RectF();
		m_Rect.top = m_position[1] - (m_scale[1] / 2);
		m_Rect.bottom = m_Rect.top + m_scale[1];
		m_Rect.left = m_position[0] - (m_scale[0] / 2);
		m_Rect.right = m_Rect.left + m_scale[0];
	}

	public boolean CheckTouch(int touchX, int touchY)
	{
		boolean touched = false;
		if(m_Rect != null)
		{
			touched = m_Rect.contains(touchX, touchY);
			if(touched)
			{
				Log.d(CButton.class.getSimpleName(), "Twas Touched at " + touchX + " " + touchY + " rect:" + m_Rect.toString());
			}
		}
		return touched;
	}
}
